<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for ASN1 Encoder Class 'asn1tsp.js'</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/sha256.js"></script>

<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../base64x-1.1.js"></script>
<script src="../asn1hex-1.1.js"></script>
<script src="../rsapem-1.1.js"></script>
<script src="../rsasign-1.2.js"></script>
<script src="../crypto-1.1.js"></script>
<script src="../keyutil-1.0.js"></script>
<script src="../asn1-1.0.js"></script>
<script src="../asn1x509-1.0.js"></script>
<script src="../asn1cms-1.0.js"></script>
<script src="../asn1tsp-1.0.js"></script>
<script src="../x509-1.1.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// _test/z4.* RSA 2048bit
var sZ4_PRVP8PPEM = 
"-----BEGIN PRIVATE KEY-----\n" + 
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDfdOqotHd55SYO\n" + 
"0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1wk2U0OK4pug4OBSJPhl09Zs6IwB8N\n" + 
"wPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz4pIb+o4ZAhVprLhR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+ 
"utjdTrPKKFUQNdc6/Ty8EeTnQEwUlsT2LAXCfEKxTn5RlRljDztS7Sfgs8VL0FPy\n" + 
"1Qi8B+dFcgRYKFrcpsVaZ1lBmXKsXDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SN\n" + 
"z+sR4zRPG85R/se5Q06Gu0BUQ3UPm67ETVZLAgMBAAGjXzBdMAwGA1UdEwEB/wQC\n" + 
"MAAwCwYDVR0PBAQDAgbAMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMIMCgGA1UdHwQh\n" + 
"MB8wHaAboBmGF2h0dHA6Ly90ZXN0LmNvbS9jYTEuY3JsMA0GCSqGSIb3DQEBBQUA\n" + 
"A4IBAQBNkm5GniFi3PKqbafCVN8mpHWJjF2stCRTVxeTCIXUC63YD5XKABGzPH+Y\n" + 
"2R8fCrOa8cGlHmFXOlJye/lnXeZodPyxJUvAKohTp6sG+rJVId8ISI2Io2i5BF8a\n" + 
"CHdm8qd8E0fJvBudqkEc26Ia6tFSA/gEW0ffhsCkN/lXUAjuvDLqtTtU7zBU6dIl\n" + 
"h12Pwyf+x6AsYSciA9zWC6OE590K8Jr2z4u85biM7viWvPeZPNHSNM1fe+8wKbP8\n" + 
"64JtLj/VrglcsXALaUalyh2Hs7gPQzjyus1fyhEWPO3T6KMcBMXjb6anxL5q9YO5\n" + 
"qx1hJTY3L1hahBcMTALQyTEiFv1S\n" + 
"-----END CERTIFICATE-----\n";

// ======= TEST ===============================================================

test("Accuracy", function() {
  expect(2);

  var o = new KJUR.asn1.tsp.Accuracy({seconds: 7, millis: 7, micros: 7});
  equal(o.getEncodedHex(), "3009020107800107810107", "");

  var o2 = new KJUR.asn1.tsp.Accuracy({millis: 500});
  equal(o2.getEncodedHex(), "3004800201f4", "");
});

test("MessageImprint", function() {
  expect(1);
  var o = new KJUR.asn1.tsp.MessageImprint({hashAlg: 'sha256', hashValue: 'a1a2a3a4a5a6a7a8'});
  equal(o.getEncodedHex(), "3019300d060960864801650304020105000408a1a2a3a4a5a6a7a8", "");
});

test("TSTInfo", function() {
  expect(1);
  var o = new KJUR.asn1.tsp.TSTInfo({
    policy: '1.2.3.4.5',
    messageImprint: { hashAlg: 'sha1', hashValue: 'a1a2a3a4' },
    serialNumber: {'int': 3},
    genTime: {str: '20131231235959.123Z', millis: true},
    //genTime: {},
    accuracy: { millis: 500 },
    ordering: true,
    nonce: {'int': 3},
    tsa: {'str': '/C=US/O=TSP1'}
  });
  equal(o.getEncodedHex(), "305e02010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103301c310b3009060355040613025553310d300b060355040a0c0454535031", "");
});

test("PKIStatus", function() {
  expect(2);

  var o = new KJUR.asn1.tsp.PKIStatus({int: 0});
  equal(o.getEncodedHex(), "020100", "by int 0");

  var o2 = new KJUR.asn1.tsp.PKIStatus({name: 'granted'});
  equal(o2.getEncodedHex(), "020100", "by name granted");
});

test("PKIFreeText", function() {
  var o = new KJUR.asn1.tsp.PKIFreeText({array: ['aaa', 'bbb']});
  equal(o.getEncodedHex(), "300a0c036161610c03626262", "by [aaa, bbb]");
});

test("PKIFailureInfo", function() {
  expect(2);

  var o = new KJUR.asn1.tsp.PKIFailureInfo({int: 25});
  equal(o.getEncodedHex(), "030203c8", "by int 25");

  var o2 = new KJUR.asn1.tsp.PKIFailureInfo({name: 'systemFailure'});
  equal(o2.getEncodedHex(), "030203c8", "by name systemFailure");
});

test("PKIStatusInfo", function() {
  var o = new KJUR.asn1.tsp.PKIStatusInfo({
    status: {name: 'rejection'},
    statstr: ['aaa'],
    failinfo: {name: 'badAlg'}
  });
  equal(o.getEncodedHex(), "300d02010230050c03616161030100", "");
});

test("TSPUtil.newTimeStampToken", function() {
  var o = KJUR.asn1.tsp.TSPUtil.newTimeStampToken({
    tstInfo: {
      policy: '1.2.3.4.5',
      messageImprint: { hashAlg: 'sha256', hashValue: 'a1a2a3a4' },
      serialNumber: {'int': 3},
      //genTime: {millis: true},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: {millis: 500},
      ordering: true,
      nonce: {'int': 3},
      tsa: {'str': '/C=US/O=TSP1'}
    },
    certs: [sZ4_CERPEM],
    signerCert: sZ4_CERPEM,
    hashAlg: 'sha256',
    signerPrvKey: sZ4_PRVP8PPEM,
    sigAlg: 'SHA256withRSA'
  });
  equal(o.getContentInfoEncodedHex(), "308205a106092a864886f70d010702a08205923082058e020101310f300d060960864801650304020105003075060b2a864886f70d0109100104a0660464306202010106042a0304053015300d060960864801650304020105000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103301c310b3009060355040613025553310d300b060355040a0c0454535031a082031530820311308201f9a00302010202014d300d06092a864886f70d0101050500301b310b3009060355040613025553310c300a060355040a0c03434131301e170d3133303530313233353935395a170d3233303530313233353935395a301c310b3009060355040613025553310d300b06035504030c045453413130820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a35f305d300c0603551d130101ff04023000300b0603551d0f0404030206c030160603551d250101ff040c300a06082b0601050507030830280603551d1f0421301f301da01ba0198617687474703a2f2f746573742e636f6d2f6361312e63726c300d06092a864886f70d010105050003820101004d926e469e2162dcf2aa6da7c254df26a475898c5dacb424535717930885d40badd80f95ca0011b33c7f98d91f1f0ab39af1c1a51e61573a52727bf9675de66874fcb1254bc02a8853a7ab06fab25521df08488d88a368b9045f1a087766f2a77c1347c9bc1b9daa411cdba21aead15203f8045b47df86c0a437f9575008eebc32eab53b54ef3054e9d225875d8fc327fec7a02c61272203dcd60ba384e7dd0af09af6cf8bbce5b88ceef896bcf7993cd1d234cd5f7bef3029b3fceb826d2e3fd5ae095cb1700b6946a5ca1d87b3b80f4338f2bacd5fca11163cedd3e8a31c04c5e36fa6a7c4be6af583b9ab1d612536372f585a84170c4c02d0c9312216fd52318201e6308201e20201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a08198301806092a864886f70d010903310b06092a864886f70d010701302f06092a864886f70d010904312204206a406164d3957a11066a3d880b463102691f476c91832eb8f2cb75642db3fb53304b060b2a864886f70d010910020c313c303a3038041439c9062cec9d6c9f2a54326729032a5843054f9e3020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06092a864886f70d01010b05000482010005c4435c8c50d370e83b58963b2bbb603daabd0c88ba11d6b529b6052093da7d10010553ef4d6b583ec6c7ac9226c038dfa78fc8dccc9e1456ee514ffb56bf21f108b9ed8538f4b55fef4bf63049a4cf158cec1c4b83c14060201fbeec23d78eee31e13d2fcfe56b1d51c7729f7e410e355ba755c87a71db24b40d69e40baecc7316e240e708e9ab3203097b50385b6f928bd4bd37fc4b15bb30587cd91c459d77030733243245f3df3e51641e8493e23c92f90c683202f7ffee0bdfe8931204c15c777117bde9964fb4102c839b379eaae13215f54c4d5e83c9d9edec9afea6a54ee1531fb1c6fdaf55a1407998d136745d87b137e2d16c57c1acf2600bdadd", "");
});

test("TimeStampResp", function() {
  var dTST = KJUR.asn1.tsp.TSPUtil.newTimeStampToken({
    tstInfo: {
      policy: '1.2.3.4.5',
      messageImprint: { hashAlg: 'sha256', hashValue: 'a1a2a3a4' },
      serialNumber: {'int': 3},
      //genTime: {millis: true},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: {millis: 500},
      ordering: true,
      nonce: {'int': 3},
      tsa: {'str': '/C=US/O=TSP1'}
    },
    certs: [sZ4_CERPEM],
    signerCert: sZ4_CERPEM,
    hashAlg: 'sha256',
    signerPrvKey: sZ4_PRVP8PPEM,
    sigAlg: 'SHA256withRSA'
  });
  
  var o = new KJUR.asn1.tsp.TimeStampResp({tst: dTST,
                                           status: {status: {name: 'granted'}}});
  equal(o.getEncodedHex(), "308205aa3003020100308205a106092a864886f70d010702a08205923082058e020101310f300d060960864801650304020105003075060b2a864886f70d0109100104a0660464306202010106042a0304053015300d060960864801650304020105000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103301c310b3009060355040613025553310d300b060355040a0c0454535031a082031530820311308201f9a00302010202014d300d06092a864886f70d0101050500301b310b3009060355040613025553310c300a060355040a0c03434131301e170d3133303530313233353935395a170d3233303530313233353935395a301c310b3009060355040613025553310d300b06035504030c045453413130820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a35f305d300c0603551d130101ff04023000300b0603551d0f0404030206c030160603551d250101ff040c300a06082b0601050507030830280603551d1f0421301f301da01ba0198617687474703a2f2f746573742e636f6d2f6361312e63726c300d06092a864886f70d010105050003820101004d926e469e2162dcf2aa6da7c254df26a475898c5dacb424535717930885d40badd80f95ca0011b33c7f98d91f1f0ab39af1c1a51e61573a52727bf9675de66874fcb1254bc02a8853a7ab06fab25521df08488d88a368b9045f1a087766f2a77c1347c9bc1b9daa411cdba21aead15203f8045b47df86c0a437f9575008eebc32eab53b54ef3054e9d225875d8fc327fec7a02c61272203dcd60ba384e7dd0af09af6cf8bbce5b88ceef896bcf7993cd1d234cd5f7bef3029b3fceb826d2e3fd5ae095cb1700b6946a5ca1d87b3b80f4338f2bacd5fca11163cedd3e8a31c04c5e36fa6a7c4be6af583b9ab1d612536372f585a84170c4c02d0c9312216fd52318201e6308201e20201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a08198301806092a864886f70d010903310b06092a864886f70d010701302f06092a864886f70d010904312204206a406164d3957a11066a3d880b463102691f476c91832eb8f2cb75642db3fb53304b060b2a864886f70d010910020c313c303a3038041439c9062cec9d6c9f2a54326729032a5843054f9e3020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06092a864886f70d01010b05000482010005c4435c8c50d370e83b58963b2bbb603daabd0c88ba11d6b529b6052093da7d10010553ef4d6b583ec6c7ac9226c038dfa78fc8dccc9e1456ee514ffb56bf21f108b9ed8538f4b55fef4bf63049a4cf158cec1c4b83c14060201fbeec23d78eee31e13d2fcfe56b1d51c7729f7e410e355ba755c87a71db24b40d69e40baecc7316e240e708e9ab3203097b50385b6f928bd4bd37fc4b15bb30587cd91c459d77030733243245f3df3e51641e8493e23c92f90c683202f7ffee0bdfe8931204c15c777117bde9964fb4102c839b379eaae13215f54c4d5e83c9d9edec9afea6a54ee1531fb1c6fdaf55a1407998d136745d87b137e2d16c57c1acf2600bdadd", "");
});

test("TimeStampReq", function() {
  var nT = KJUR.asn1.tsp;
  expect(2);
  
  var o = new nT.TimeStampReq({
    mi: new nT.MessageImprint({hashAlg: 'sha256', hashValue: 'a1a2a3a4'}),
    policy: {oid: '1.2.3.4.5'},
    nonce: {hex: '9abcf318'},
    certreq: false
  });
  equal(o.getEncodedHex(), "30260201013015300d060960864801650304020105000404a1a2a3a406042a03040502049abcf318", "by mi obj");

  var o2 = new nT.TimeStampReq({
    mi: {hashAlg: 'sha256', hashValue: 'a1a2a3a4'},
    policy: {oid: '0.1.1.2.2'},
    nonce: {hex: '8a8b8c8d8e8f'},
    certreq: true
  });
  equal(o2.getEncodedHex(), "302b0201013015300d060960864801650304020105000404a1a2a3a406040101020202068a8b8c8d8e8f0101ff", "by mi param");
});

test("TSPUtil.parseTimeStampReq", function() {
  expect(18);

  // test TimeStampReq o
  var hex1 = "30260201013015300d060960864801650304020105000404a1a2a3a406042a03040502049abcf318";
  var j1 = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq(hex1);
  equal(typeof j1, "object", "j1");
  equal(j1.mi.hashAlg, "sha256", "mi.hashAlg=sha256");
  equal(j1.mi.hashValue, "a1a2a3a4", "mi.hashValue=a1a2a3a4");
  equal(j1.policy, "1.2.3.4.5", "mi.policy=1.2.3.4.5");
  equal(j1.nonce, "9abcf318", "nonce=9abcf318");
  equal(j1.certreq, false, "certreq=false");

  var hex2 = "302b0201013015300d060960864801650304020105000404a1a2a3a406040101020202068a8b8c8d8e8f0101ff";
  var j2 = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq(hex2);
  equal(typeof j2, "object", "j2");
  equal(j2.mi.hashAlg, "sha256", "mi.hashAlg=sha256");
  equal(j2.mi.hashValue, "a1a2a3a4", "mi.hashValue=a1a2a3a4");
  equal(j2.policy, "0.1.1.2.2", "mi.policy=0.1.1.2.2");
  equal(j2.nonce, "8a8b8c8d8e8f", "nonce=8a8b8c8d8e8f");
  equal(j2.certreq, true, "certreq=true");

  var hex3 = "304c0201013031300d0609608648016503040201050004209834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f006042a030405020b1a1b1c1e1f2a2b2c2d2e2f0101ff";
  var j3 = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq(hex3);
  equal(typeof j3, "object", "j3");
  equal(j3.mi.hashAlg, "sha256", "mi.hashAlg=sha256");
  equal(j3.mi.hashValue, "9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0", "mi.hashValue=9834...");
  equal(j3.policy, "1.2.3.4.5", "mi.policy=1.2.3.4.5");
  equal(j3.nonce, "1a1b1c1e1f2a2b2c2d2e2f", "nonce=1a1b...");
  equal(j3.certreq, true, "certreq=true");
});

test("FixedTSAAdapter", function() {
  var tstaaa = "308205c006092a864886f70d010702a08205b1308205ad020101310f300d06096086480165030402010500308193060b2a864886f70d0109100104a08183048180307e02010106042a0304053031300d0609608648016503040201050004209834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0020103181332303133313233313233353935392e3132335a3004800201f40101ff020103301c310b3009060355040613025553310d300b060355040a0c0454535031a082031530820311308201f9a00302010202014d300d06092a864886f70d0101050500301b310b3009060355040613025553310c300a060355040a0c03434131301e170d3133303530313233353935395a170d3233303530313233353935395a301c310b3009060355040613025553310d300b06035504030c045453413130820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a35f305d300c0603551d130101ff04023000300b0603551d0f0404030206c030160603551d250101ff040c300a06082b0601050507030830280603551d1f0421301f301da01ba0198617687474703a2f2f746573742e636f6d2f6361312e63726c300d06092a864886f70d010105050003820101004d926e469e2162dcf2aa6da7c254df26a475898c5dacb424535717930885d40badd80f95ca0011b33c7f98d91f1f0ab39af1c1a51e61573a52727bf9675de66874fcb1254bc02a8853a7ab06fab25521df08488d88a368b9045f1a087766f2a77c1347c9bc1b9daa411cdba21aead15203f8045b47df86c0a437f9575008eebc32eab53b54ef3054e9d225875d8fc327fec7a02c61272203dcd60ba384e7dd0af09af6cf8bbce5b88ceef896bcf7993cd1d234cd5f7bef3029b3fceb826d2e3fd5ae095cb1700b6946a5ca1d87b3b80f4338f2bacd5fca11163cedd3e8a31c04c5e36fa6a7c4be6af583b9ab1d612536372f585a84170c4c02d0c9312216fd52318201e6308201e20201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a08198301806092a864886f70d010903310b06092a864886f70d010701302f06092a864886f70d01090431220420b0a206fa135a194d64514e496c143afc3b4284a07303e6df26c482a14c81b124304b060b2a864886f70d010910020c313c303a3038041439c9062cec9d6c9f2a54326729032a5843054f9e3020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06092a864886f70d01010b05000482010091db4eb9666c15ed9f9a0fb2c517c570641c15ea91d347af174814b85b5fc6abcda415d123a905feac79a5be881eca157296d5d5a87c563ae7982fe8db52b10c635ccf54e534c2351a356a26294a4c3dcaaddb67154ba8033645c13660670ca27c07eef9ee062d49983c30ebaa7c03034be684af80bd08532f45a8d17c9857d5190e57ab41f90238e176f5afc0b40c848ec9f365d39501289e787d28a8428518c9a3e5e6eba89c196ed95cf82c88f4b4cdb7c11894285a120941a92a61e250ef45a4345eefc2f696b16318c3c6d9d0ceebedb95389d5228cd24532c210ab96fd2737f171c08cd48199de9ee7b55dd0a3b1d8610ee9c40d50c2958fc2f8025ed3";

  var tstbbb = "308205c006092a864886f70d010702a08205b1308205ad020101310f300d06096086480165030402010500308193060b2a864886f70d0109100104a08183048180307e02010106042a0304053031300d0609608648016503040201050004203e744b9dc39389baf0c5a0660589b8402f3dbb49b89b3e75f2c9355852a3c677020103181332303133313233313233353935392e3132335a3004800201f40101ff020103301c310b3009060355040613025553310d300b060355040a0c0454535031a082031530820311308201f9a00302010202014d300d06092a864886f70d0101050500301b310b3009060355040613025553310c300a060355040a0c03434131301e170d3133303530313233353935395a170d3233303530313233353935395a301c310b3009060355040613025553310d300b06035504030c045453413130820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a35f305d300c0603551d130101ff04023000300b0603551d0f0404030206c030160603551d250101ff040c300a06082b0601050507030830280603551d1f0421301f301da01ba0198617687474703a2f2f746573742e636f6d2f6361312e63726c300d06092a864886f70d010105050003820101004d926e469e2162dcf2aa6da7c254df26a475898c5dacb424535717930885d40badd80f95ca0011b33c7f98d91f1f0ab39af1c1a51e61573a52727bf9675de66874fcb1254bc02a8853a7ab06fab25521df08488d88a368b9045f1a087766f2a77c1347c9bc1b9daa411cdba21aead15203f8045b47df86c0a437f9575008eebc32eab53b54ef3054e9d225875d8fc327fec7a02c61272203dcd60ba384e7dd0af09af6cf8bbce5b88ceef896bcf7993cd1d234cd5f7bef3029b3fceb826d2e3fd5ae095cb1700b6946a5ca1d87b3b80f4338f2bacd5fca11163cedd3e8a31c04c5e36fa6a7c4be6af583b9ab1d612536372f585a84170c4c02d0c9312216fd52318201e6308201e20201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a08198301806092a864886f70d010903310b06092a864886f70d010701302f06092a864886f70d01090431220420e9ab1694a8a686650f0e1df0b880753084489100dfd12fdb42ed96ad702d38ca304b060b2a864886f70d010910020c313c303a3038041439c9062cec9d6c9f2a54326729032a5843054f9e3020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06092a864886f70d01010b0500048201007496e3825115891a1f451d40a9968783e8d92210f985e2498170130b2bdf9cee69721f5600066374a5edba8673b9c23176551e70bfe7f9e0ca0f569c25402108e77bafa41d824c73ee45253a64d5c93adf0513f6fadfb69992f344a379de3a292d23056b642a6e0970559f7881f8660eaa2f9670b77328f1b882ce78e0ace222a3004444751b518ef82befc19e39c928cbbd97cb53dc80415163c3a99e3f504ea41a8cda75a0b5ebcbece174a03816344c9caa4c298d23c7352d7f1dda56495bd1a865ff60fbb098a21ecd3d08d916840ad40e5c0dbb66927f84a678c7d4565beef4f623a521b53f3ea97c4155d1a0802656edaa50b07c6704d544fbc5fd43e1";

  var tsa = new KJUR.asn1.tsp.FixedTSAAdapter({
    tstInfo: {
      policy: '1.2.3.4.5',
      messageImprint: {},
      serialNumber: {'int': 3},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: {millis: 500},
      ordering: true,
      nonce: {'int': 3},
      tsa: {'str': '/C=US/O=TSP1'}
    },
    certs: [sZ4_CERPEM],
    signerCert: sZ4_CERPEM,
    hashAlg: 'sha256',
    signerPrvKey: sZ4_PRVP8PPEM,
    sigAlg: 'SHA256withRSA'
  });

  expect(4);
  equal(tsa.getTSTHex('616161', 'sha256'), tstaaa, 'aaa 1');
  equal(tsa.getTSTHex('616161', 'sha256'), tstaaa, 'aaa 2');
  equal(tsa.getTSTHex('626262', 'sha256'), tstbbb, 'bbb 1');
  equal(tsa.getTSTHex('626262', 'sha256'), tstbbb, 'bbb 2');
});

test("SimpleTSAAdapter", function() {
  var tsa = new KJUR.asn1.tsp.SimpleTSAAdapter({
    tstInfo: {
      policy: '1.2.3.4.5',
      messageImprint: {},
      serialNumber: {'int': 3},
      genTime: {millis: true},
      accuracy: {millis: 500},
      ordering: true,
      nonce: {'int': 3},
      tsa: {'str': '/C=US/O=TSP1'}
    },
    certs: [sZ4_CERPEM],
    signerCert: sZ4_CERPEM,
    hashAlg: 'sha256',
    signerPrvKey: sZ4_PRVP8PPEM,
    sigAlg: 'SHA256withRSA'
  });

  expect(4);
  equal(tsa.getTSTHex('616161', 'sha256').substr(0, 2), '30', 'aaa 1');
  equal(tsa.getTSTHex('616161', 'sha256').substr(0, 2), '30', 'aaa 2');
  equal(tsa.getTSTHex('626262', 'sha256').substr(0, 2), '30', 'bbb 1');
  equal(tsa.getTSTHex('626262', 'sha256').substr(0, 2), '30', 'bbb 2');
});


});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<div>
QUnit TEST 
<a href="qunit-do-asn1.html">asn1</a> | 
<a href="qunit-do-asn1x509.html">asn1x509</a> | 
<a href="qunit-do-asn1cms.html">asn1cms</a> | 
<a href="qunit-do-asn1tsp.html">asn1tsp</a> | 
<a href="../api/index.html">APIDOCS</a> | 
</div>
</body>
</html>
